// source --> https://giant.vn/wp-content/themes/flatsome-child/toan-nguyen/js/js_binh_luan.js
jQuery(function ($) {
$(document).keyup(function(e){
if( e.key === "Escape" ){
$(".modal_div_comment").hide();
}
})
$(document).on('click', '.captcha_reset_chuan', function(event){
event.preventDefault();
my_this = $(this);
data = {
'action' : 'get_captcha',
'nonce' : nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function(response){
my_this.closest(".div_check_captcha").find('.cap_img').attr('src',response.mysrc );
my_this.closest(".div_check_captcha").find('.input_captcha').val("");
},
});
});
$(document).on('click', '.xem_xd', function(){
$(this).hide();
$(this).parent().find(".p_xem_them_xd").show();
});
$(document).on('change', 'input[name="add_image_star[]"]', function(){
my_this = $(this);
my_this_parent = my_this.closest(".div_nhap_rating");
file_data = $(this);
form_data = new FormData();
var totalimage = document.getElementById('image_upload_star').files.length;
for(var index = 0; index < totalimage; index++ ){
form_data.append('add_image[]', document.getElementById('image_upload_star').files[index] );
}
var bl_is_start = ( my_this.closest(".div_nhap_rating").find(".div_wap_show_image_comment").length <= 0) ? true : false;
form_data.append('action', 'file_image_callback_star');
form_data.append('bl_is_start', bl_is_start );
$.ajax({
dataType: 'json',
url: ajaxurl,
type: 'POST',
contentType: false,
processData: false,
data: form_data,
beforeSend: function(){
$("#overlay").show();
my_this.prop('disabled', true);
},
success: function(response){
if (response.is_no_error) {
my_decode = JSON.parse( response.value_obj );
if( my_decode.length > 0){
if($(".div_nhap_rating").find(".div_wap_show_image_comment").length > 0){
item_show_img_ajax = "";
my_decode.forEach(function(value){
item_show_img_ajax += "
"+
"
×"+
"
"+
"
";
});
my_this_parent.find(".div_wap_show_image_comment").html(item_show_img_ajax);
}else{
mul_div_shom_img = "";
my_this_parent.find(".div_ajax_show_image_comment").html(mul_div_shom_img);
}
}
} else {
if( response.mes_error === "trensauhinh" ){
alert("Xin quý khách vui lòng gửi không quá 6 hình");
}else if( response.mes_error === "filequalon" ){
alert("Xin quý khách vui lòng gửi hình không quá 5 MB");
}else if( response.mes_error === "khonglahinh" ){
alert("Xin quý khách vui lòng gửi hình ảnh");
}
console.log("Loi them hinh anh");
console.log(response);
}
my_this.val('');
my_this.prop('disabled', false);
$("#overlay").hide();
},
error: function (jqXHR, textStatus, errorThrown) {
my_this.prop('disabled', false);
console.log(jqXHR + " :: " + textStatus + " :: " + errorThrown);
my_this.val('');
$("#overlay").hide();
},
});
});
$(document).on('click', '.xoa_image_ajax_star', function(){
my_this = $(this);
id_att = my_this.closest(".show_image_ajax").find(".class_add_image").attr("id_att");
my_this_parent = my_this.closest(".div_nhap_rating");
data = {
'nonce': nonce,
'action': 'remove_image_callback_star',
'id_att': id_att,
}
$.ajax({
dataType: 'json',
url: ajaxurl,
type: 'POST',
data: data,
success: function (response) {
if( response.is_no_error){
my_decode = JSON.parse( response.value_obj );
mul_div_shom_img = "";
console.log( response.value_obj );
my_decode.forEach(function(value){
div_show_img_comment = ""+
"
×"+
"
"+
"
";
mul_div_shom_img += div_show_img_comment;
});
my_this_parent.find(".div_wap_show_image_comment").html(mul_div_shom_img);
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(" loi khi xoa hinh ");
}
});
});
//
$(document).on('click', '.xoa_image_ajax', function(){
my_this = $(this);
my_this_parent = my_this.closest(".div_input_binh_luan");
id_att = my_this.closest(".show_image_ajax").find(".class_add_image").attr("id_att");
data = {
'nonce': nonce,
'action': 'remove_image_callback',
'id_att': id_att,
}
$.ajax({
dataType: 'json',
url: ajaxurl,
type: 'POST',
data: data,
success: function (response) {
if( response.is_no_error){
my_decode = JSON.parse( response.value_obj );
mul_div_shom_img = "";
console.log( response.value_obj );
my_decode.forEach(function(value){
div_show_img_comment = ""+
"
×"+
"
"+
"
";
mul_div_shom_img += div_show_img_comment;
});
my_this_parent.find(".div_wap_show_image_comment").html(mul_div_shom_img);
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(" loi khi xoa hinh ");
}
});
});
$(document).on('change', 'input[name="add_image_bl[]"]', function(){
my_this = $(this);
my_this_parent = my_this.closest(".div_input_binh_luan");
file_data = $(this);
form_data = new FormData();
var totalimage = document.getElementById('image_upload_bl').files.length;
for(var index = 0; index < totalimage; index++ ){
form_data.append('add_image[]', document.getElementById('image_upload_bl').files[index] );
}
var bl_is_start = ( my_this.closest(".div_input_binh_luan").find(".div_wap_show_image_comment").length <= 0) ? true : false;
form_data.append('action', 'file_image_callback');
form_data.append('bl_is_start', bl_is_start );
$.ajax({
dataType: 'json',
url: ajaxurl,
type: 'POST',
contentType: false,
processData: false,
data: form_data,
beforeSend: function(){
my_this.prop('disabled', true);
$("#overlay").show();
},
success: function (response) {
if (response.is_no_error) {
my_decode = JSON.parse( response.value_obj );
if( my_decode.length > 0){
if($(".div_input_binh_luan").find(".div_wap_show_image_comment").length > 0){
item_show_img_ajax = "";
my_decode.forEach(function(value){
item_show_img_ajax += ""+
"
×"+
"
"+
"
";
});
$(".div_input_binh_luan").find(".div_wap_show_image_comment").html(item_show_img_ajax);
}else{
mul_div_shom_img = "";
my_this_parent.find(".div_ajax_show_image_comment").html(mul_div_shom_img);
}
}
} else {
if( response.mes_error === "trensauhinh" ){
alert("Xin quý khách vui lòng gửi không quá 4 hình");
}else if( response.mes_error === "filequalon" ){
alert("Xin quý khách vui lòng gửi hình không quá 5 MB");
}else if( response.mes_error === "khonglahinh" ){
alert("Xin quý khách vui lòng gửi hình ảnh");
}
console.log("Loi them hinh anh");
console.log(response);
}
my_this.val('');
my_this.prop('disabled', false);
$("#overlay").hide();
},
error: function (jqXHR, textStatus, errorThrown) {
my_this.prop('disabled', false);
console.log(jqXHR + " :: " + textStatus + " :: " + errorThrown);
my_this.val('');
$("#overlay").hide();
}
});
});
$("#id_btn_huy_danh_gia").click(function () {
$("#div_nhap_rating").hide();
});
$('#id_content_binh_luan_duoi').click(function(){
$(".div_tra_loi_binh_luan").hide();
va_bien = $("#wap_support_comment_duoi").is(":visible");
if (va_bien === false) {
$("#wap_support_comment_duoi").show( 0, function () {
data = {
'action': 'get_captcha',
'nonce': nonce,
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
console.log(response);
$("#capImage").attr("src", response.mysrc);
},
});
});
}else{
console.log( va_bien );
}
});
$(".captcha_reset").click(function(event){
my_this = $(this);
event.preventDefault();
data = {
'action' : 'get_captcha',
'nonce' : nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function(response){
my_this.parent().find('#capImage').attr('src',response.mysrc );
},
});
});
$(document).on('click', '.captcha_reset_tl', function(event){
my_this = $(this);
event.preventDefault();
data = {
'action' : 'get_captcha',
'nonce' : nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function(response){
my_this.parent().find('.capImage_tl').attr('src',response.mysrc );
},
});
});
$('.rate-btn').hover(function () {
$('.rate-btn').removeClass('rate-btn-hover');
var therate = $(this).attr('id');
for (var i = therate; i >= 0; i--) {
$('.rate-btn-' + i).addClass('rate-btn-hover');
}
;
});
// cho tat ca ve mac dinh khi chua click
$(".div_in_star").mouseout(function () {
var i = 5;
for (var i = 5; i >= 0; i--) {
$('.rate-btn-' + i).removeClass('rate-btn-hover');
}
});
$('.rate-btn').click(function () {
var therate = $(this).attr('id');
var dataRate = 'act=rate&product_id=&rate=' + therate; //
$('.rate-btn').removeClass('rate-btn-active');
for (var i = therate; i >= 0; i--) {
$('.rate-btn-' + i).addClass('rate-btn-active');
}
$('input[name="num_star"]').val(therate);
});
$(document).on('click', '.img_commment', function(){
my_this = $(this);
my_this.closest('.div_show_image').find('.img_commment_modal').attr("src", my_this.attr("src"));
my_this.closest(".div_show_image").find(".modal_div_comment").show();
});
$(document).on('click', '.close_modal_img', function(){
$(this).closest(".modal_div_comment").hide();
});
var pageNumber_star = 1;
$(document).on('click', '#xem_them_star', function(){
my_this = $(this);
pageNumber_star++;
var str = 'pageNumber=' + pageNumber_star + '&action=more_danhgia_ajax&nonce='+ nonce + '&id_post=' + my_this.attr("id_post");
$.ajax({
type: "POST",
dataType: "json",
url: ajaxurl,
data: str,
beforeSend: function () {
my_this.attr("disabled", true);
my_this.html("Đang tải");
},
success: function (response) {
console.log( response );
if(response.html_ajax){
$(".div_wrap_item_danh_gia").append(response.html_ajax);
my_this.attr("disabled", false);
my_this.html("Tải thêm");
if( response.num_pages === 0 ){
//my_this.hide(); xoa luon
my_this.parent().remove();
}
}else{
my_this.attr("disabled", true);
my_this.html("Hết Bình Luận");
}
},
error: function (jqXHR, textStatus, errorThrown) {
$loader.html(jqXHR + " :: " + textStatus + " :: " + errorThrown);
my_this.attr("disabled", true);
}
});
});
var pageNumber_cm = 1;
$(document).on('click', '#xem_them_cm', function(){
my_this = $(this);
pageNumber_cm++;
var str = 'pageNumber=' + pageNumber_cm + '&action=more_binhluan_ajax&nonce='+ nonce + '&id_post=' + my_this.attr("id_post");
$.ajax({
type: "POST",
dataType: "json",
url: ajaxurl,
data: str,
beforeSend: function () {
my_this.attr("disabled", true);
my_this.html("Đang tải");
},
success: function (response) {
if(response.html_ajax){
$(".wap_show_binh_luan").append(response.html_ajax);
my_this.attr("disabled", false);
my_this.html("Tải thêm");
if( response.num_pages === 0 ){
//my_this.hide();// khong anh ma xoa di.
my_this.parent().remove();
}
}else{
my_this.attr("disabled", true);
my_this.html("Hết Bình Luận");
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
my_this.attr("disabled", false);
}
});
});
$(document).on('click', '.btn_tra_loi_star', function(){
event.preventDefault();
if(!is_login){
alert("Đăng nhập mới được trả lời");
}
my_this = $(this);
if( my_this.closest(".item_star_rating_item").find(".div_input_tra_loi_star")[0] ){
my_this.closest(".item_star_rating_item").find(".div_input_tra_loi_star").remove();
//my_this.closest(".item_star_rating_item").find(".div_input_tra_loi_star").toggle();
}else{
data = {
'nonce': nonce,
'action': 'show_tra_loi_star',
'id_post': my_this.attr("id"),
'id_pro': my_this.attr("id_pro"),
},
$.ajax({
type: 'POST',
dataType: 'json',
url: ajaxurl,
data: data,
beforeSend: function () {
$("#overlay").show();
},
success: function (response) {
if (response.is_no_error) {
if (my_this.closest(".item_star_rating_item").find(".div_wap_tra_loi_star").length <= 0) {
// tao
make_div = '';
make_div += response.html_ajax;
make_div += '
';
my_this.closest(".item_star_rating_item").append( make_div );
}else{
// addd
my_this.closest(".item_star_rating_item").find(".div_wap_tra_loi_star").prepend(response.html_ajax);
// none no.
}
//my_this.closest(".item_star_rating_item").append(response.html_ajax);
}
$("#overlay").hide();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
}
});
}
});
$(document).on('click', '.content_tra_loi_star', function(){
my_this = $(this);
my_this_parent = my_this.closest(".div_input_tra_loi_star");
if( my_this_parent.find(".div_check_captcha").is(":visible") === false ){
my_this_parent.find(".div_check_captcha").show(0, function(){
data = {
'action': 'get_captcha',
'nonce': nonce,
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
my_this_parent.find(".cap_img").attr("src", response.mysrc);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
}
});
});
}
});
$(document).on('click', '.btn_gui_tra_loi_star', function(){
my_this = $(this);
if(!is_login){
alert("Đăng nhập mới được trả lời");
return false;
}
my_this_parent = my_this.closest(".div_input_tra_loi_star");
data = {
'nonce': nonce,
'action': 'insert_tra_loi_star',
'id_post': my_this.attr("id_post"),
'id_pro': my_this.attr("id_pro"),
'content': my_this_parent.find("textarea[name='content_tra_loi_star']").val(),
}
if( data.content.length < 3 ){
alert("Nội dung quá ngắn");
return false;
}
if(my_this.closest(".div_input_tra_loi_star").find(".div_check_captcha").length > 0){
data.value_captcha = my_this_parent.find(".input_captcha").val();
if( data.value_captcha.length <= 0 ){
alert("Chưa nhập mã captcha");
return false;
}
}
$.ajax({
type: "POST",
dataType: "json",
url: ajaxurl,
data: data,
beforeSend: function(){
my_this.prop('disabled', true);
$("#overlay").show();
},
success: function (response) {
if( response.is_no_error){
if ((response.option_browser === "publish")) {
my_this.closest(".item_star_rating_item").find(".div_wap_tra_loi_star").append(response.html_ajax);
if( !response.qtv){
alert("Trả lời thành công. Cảm ơn bạn!");
}
} else {
alert("Trả lời đang chờ hệ thống duyệt. Cảm ơn bạn!");
}
my_this_parent.find("textarea[name='content_tra_loi_star']").val("");
my_this_parent.find(".input_captcha").val("");
my_this_parent.hide();
}else{
if(response.mes_error = "macaptchakodung"){
alert("Mã captcha không đúng");
data = {
'action' : 'get_captcha',
'nonce' : nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function(response){
my_this_parent.find(".cap_img").attr('src',response.mysrc );
my_this_parent.find(".input_captcha").val("");
},
});
}else{
console.log("Loi ko add dc");
console.log(response);
}
}
$("#overlay").hide();
my_this.prop('disabled', false);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
$("#overlay").hide();
my_this.prop('disabled', false);
}
});
});
});
function remove_image_ajax_bl() {
jQuery(function ($) {
//my_this = $(this);
id_att = my_this.closest(".show_image_ajax").find(".class_add_image").attr("id_att");
data = {
'nonce': nonce,
'action': 'remove_image_callback',
'id_att': id_att,
}
$.ajax({
dataType: 'json',
url: ajaxurl,
type: 'POST',
data: data,
success: function (response) {
if( response.is_no_error){
$(".show_image_ajax_bl").remove();
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(" loi khi xoa hinh ");
}
});
});
}
var modal_comment = document.getElementsByClassName('modal_div_comment');
var window_comment = window;
window_comment.onclick = function (event) {
if (event.target.className == "modal_div_comment") {
jQuery(function ($) {
$(".modal_div_comment").hide();
});
}
};
// source --> https://giant.vn/wp-content/themes/flatsome-child/toan-nguyen/js/js_phan_binh_luan.js
jQuery(function ($) {
/*js for commnet*/
$("#btn_binh_luan").click(function () {
my_this = $(this);
if ($('textarea[name="content_binh_luan"]').val().length < 1) {
alert("Nội dung bình luận ko hợp lệ");
return false;
}
if ($('textarea[name="content_binh_luan"]').val().length > 1143) {
alert("Nội dung bình luận quá dài");
return false;
}
get_value_captcha_this = my_this.closest(".div_input_binh_luan").find('input[name="value_captcha"]').val();
var bl_is_no_img = (my_this.closest(".div_input_binh_luan").find(".div_wap_show_image_comment").length <= 0) ? true : false;
if (get_value_captcha_this.length > 0) {
if (is_login) {
var data = {
'action': 'add_xdvncomment_fe',
'nonce': nonce,
'content_comment': $('textarea[name="content_binh_luan"]').val(),
'id_pro': id_pro_local,
'value_captcha': get_value_captcha_this,
'bl_is_no_img': bl_is_no_img,
};
if (data.content_comment.length > 2) {
$.ajax({
type: "POST",
dataType: "json",
url: ajaxurl,
data: data,
beforeSend: function () {
my_this.prop('disabled', true);
},
success: function (response) {
if (response.is_no_error) {
if (response.option_browser === "pending") {
alert("Câu hỏi đang chờ duyệt.Cảm ơn bạn đã đặt câu hỏi.");
} else {
num_tatol_bl = response.num_tatol_bl;
$(".title_tatol_num_bl").text(num_tatol_bl + " Hỏi và đáp");
my_html = response.html_ajax;
if ($(".wap_show_binh_luan").find(".div_chua_co_binh_luan").length > 0) {
// chua co item nao
$(".wap_show_binh_luan").html(my_html);
} else {
$(".wap_show_binh_luan").prepend(my_html);
if ($("#xem_them_cm").length > 0) {
// co nut moi tru
$(".item_div_binh_luan:last").remove();
}
}
alert("Chúng tôi phản hồi sớm nhất có thể. Cảm ơn bạn đã đặt câu hỏi.");
}
$('textarea[name="content_binh_luan"]').val("");
$(".div_input_binh_luan").hide();
} else {
if (response.mes_error == "macaptchakodung") {
alert("Mã captcha không đúng");
$("input[name='value_captcha']").val("");
// chay lai captcha
data = {
'action': 'get_captcha',
'nonce': nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
$('#capImage').attr('src', response.mysrc);
},
});
} else {
console.log("loi khi them binh luan");
console.log(data_obj);
}
}
my_this.prop('disabled', false);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}
});
} else {
alert("Nội dung bình luận không hợp lệ");
return false;
}
} else {
data = {
'action': 'check_captcha',
'nonce': nonce,
'value_captcha': get_value_captcha_this,
}
$.ajax({
dataType: 'json',
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
if (response.is_no_error) {
$('textarea[name="content_binh_luan_tren_modal"]').val($('textarea[name="content_binh_luan"]').val());
$('input[name="bl_is_no_img_tren_modal"]').val(bl_is_no_img);
$('input[name="value_captcha_md"]').val(get_value_captcha_this);
$("#id_modal_get_info_binh_luan").show();
$('textarea[name="content_binh_luan"]').val("");
} else {
alert("Captcha không đúng");
data = {
'action': 'get_captcha',
'nonce': nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
my_this.closest(".div_input_binh_luan").find('#capImage').attr('src', response.mysrc);
my_this.closest(".div_input_binh_luan").find("input[name='value_captcha']").val("");
},
});
}
},
});
}
} else {
alert("Phải xác nhận captcha");
return false;
}
});
$("#btn_binh_luan_modal").click(function () {
my_this = $(this);
var data = {
'action': 'add_xdvncomment_fe',
'nonce': nonce,
'content_comment': $('textarea[name="content_binh_luan_tren_modal"]').val(),
'full_nam_modal': $('input[name="full_nam_modal"]').val(),
'num_phone_bl': $('input[name="num_phone_bl"]').val(),
'email_bl': $('input[name="email_bl"]').val(),
'id_pro': id_pro_local,
'value_captcha': $('input[name="value_captcha_md"]').val(),
'bl_is_no_img': $('input[name="bl_is_no_img_tren_modal"]').val(),
};
if (data.full_nam_modal.length < 1) {
alert("Họ tên không hợp lệ");
return false;
}
var isphone = /^(1\s|1|)?((\(\d{3}\))|\d{3})(\-|\s)?(\d{3})(\-|\s)?(\d{4})$/.test(data.num_phone_bl);
if (!isphone) {
alert("Số điện thoại không hợp lệ");
return false;
}
const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!re.test(data.email_bl)) {
alert("Email không hợp lệ");
return false;
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
beforeSend: function () {
my_this.prop('disabled', true);
},
success: function (response) {
if (response.is_no_error) {
if (response.option_browser === "pending") {
alert("Câu hỏi đang chờ duyệt.Cảm ơn bạn đã đặt câu hỏi.");
} else {
my_html = response.html_ajax;
num_tatol_bl = response.num_tatol_bl;
$(".title_tatol_num_bl").text(num_tatol_bl + " Hỏi và đáp");
if ($(".wap_show_binh_luan").find(".div_chua_co_binh_luan").length > 0) {
$(".wap_show_binh_luan").html(my_html);
} else {
$(".wap_show_binh_luan").prepend(my_html);
if ($("#xem_them_cm").length > 0) {
// co nut moi tru
$(".item_div_binh_luan:last").remove();
}
}
// xu ly phan trang
//neu tong so binh luan lon hon so hien tren mot trang
//
alert("Chúng tôi phản hồi sớm nhất có thể. Cảm ơn bạn đã đặt câu hỏi.");
}
$('#id_modal_get_info_binh_luan').hide();
$('textarea[name="content_binh_luan"]').val("");
$('input[name="full_nam_modal"]').val();
$('input[name="num_phone_bl"]').val();
$('input[name="email_bl"]').val();
$('input[name="value_captcha_md"]').val();
$(".div_input_binh_luan").hide();
} else {
console.log("loi khi them binh luan");
console.log(data_obj);
}
my_this.prop('disabled', false);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR + " :: " + textStatus + " :: " + errorThrown);
},
});
});
$("#btn_huy_modal_get_binh_luan").click(function () {
$("#id_modal_get_info_binh_luan").hide();
});
$("#btn_huy_modal_get_binh_luan_tra_loi").click(function () {
$("#id_modal_get_info_binh_luan_tra_loi").hide();
});
$(document).on('click', '.btn_tra_loi_bm', function () {
$("#wap_support_comment_duoi").hide();
$(".div_tra_loi_binh_luan").hide();
my_this = $(this);
get_value_name = my_this.attr("id-name");
my_this.parent().parent().find('textarea[name="content_binh_luan_tra_loi"]').text(get_value_name);
my_this.parent().parent().find('.btn_binh_luan_tra_loi').attr("id_string_dau", get_value_name);
my_this.parent().parent().children('.div_tra_loi_binh_luan').toggle(0, function () {
data = {
'action': 'get_captcha',
'nonce': nonce,
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
console.log(response);
my_this.parent().parent().find('.capImage_tl').attr('src', response.mysrc);
},
});
});
});
$(document).on('click', '.btn_binh_luan_tra_loi', function () {
my_this = $(this);
id_string_dau = my_this.attr('id_string_dau').length;
get_value_content_binh_luan_tra_loi = $(this).closest('.div_tra_loi_binh_luan').find('textarea[name="content_binh_luan_tra_loi"]').val();
if (get_value_content_binh_luan_tra_loi.length < (id_string_dau + 2)) {
alert("Nội dung bình luận không hợp lệ");
return false;
}
if (get_value_content_binh_luan_tra_loi.length > 1143) {
alert("Nội dung bình luận quá dài");
return false;
}
if (my_this.parent().find('input[name="value_captcha_tl"]').length > 0) {
if ($(this).parent().find('input[name="value_captcha_tl"]').val() <= 0) {
alert("Captcha không hợp lệ");
return false;
}
}
get_parent_content_binh_luan_tra_loi = $(this).attr("id_parent");
var my_this_html = $(this);
captcha_tl = $(this).parent().find('input[name="value_captcha_tl"]').val();
if (is_login) {
var data = {
'action': 'add_xdvncomment_tra_loi_fe',
'nonce': nonce,
'content_binh_luan_tra_loi': get_value_content_binh_luan_tra_loi,
'id_comment_parent': $(this).attr("id_parent"),
'id_pro': id_pro_local,
};
if (my_this.parent().find('input[name="value_captcha_tl"]').length > 0) {
data.value_captcha = $(this).parent().find('input[name="value_captcha_tl"]').val();
}
if (data.content_binh_luan_tra_loi.length > 2) {
$.ajax({
dataType: 'json',
type: "POST",
url: ajaxurl,
data: data,
beforeSend: function () {
my_this.prop('disabled', true);
},
success: function (response) {
if (response.is_no_error) {
if (response.option_browser === "pending") {
alert("Trả lời đang chờ duyệt.Cảm ơn bạn đã trả lời.");
} else {
m_this_item = $("#id_item_div_binh_luan_" + response.id_parent);
if (m_this_item.find(".div_wap_show_tra_loi_bt").length <= 0) {
var my_html_append = '' + response.html_ajax + '
';
m_this_item.append(my_html_append);
} else {
m_this_item.find(".div_wap_show_tra_loi_bt").append(response.html_ajax);
}
if (!response.qtv) {
alert("Cảm ơn bạn đã đặt câu hỏi. Chúng tôi sẽ phản hồi sớm nhất.");
}
}
my_this.closest('.div_tra_loi_binh_luan').find('textarea[name="content_binh_luan_tra_loi"]').val("");
my_this.closest('.div_tra_loi_binh_luan').find('input[name="value_captcha_tl"]').val("");
my_this_html.closest(".div_tra_loi_binh_luan").hide();
} else {
if (response.mes_error === "macaptchakodung") {
alert("Mã captcha không đúng");
data = {
'action': 'get_captcha',
'nonce': nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
my_this.closest('.div_tra_loi_binh_luan').find('.capImage_tl').attr('src', response.mysrc);
my_this.closest('.div_tra_loi_binh_luan').find('.input_captcha_tl').val('');
},
});
} else {
console.log("loi khi them binh luan");
console.log(data_obj);
}
}
my_this.prop('disabled', false);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}
});
} else {
alert("Nội dung bình luận không hợp lệ");
return false;
}
} else {
data = {
'action': 'check_captcha',
'nonce': nonce,
'value_captcha': captcha_tl,
}
$.ajax({
dataType: 'json',
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
if (response.is_no_error) {
$("#id_modal_get_info_binh_luan_tra_loi").find('textarea[name="content_binh_luan_tra_loi_in_modal"]').val(get_value_content_binh_luan_tra_loi);
$("#id_modal_get_info_binh_luan_tra_loi").find('input[name="parent_modal_tra_loi"]').val(get_parent_content_binh_luan_tra_loi);
$("#id_modal_get_info_binh_luan_tra_loi").find('input[name="captcha_tra_loi_in_md"]').val(captcha_tl);
$("#id_modal_get_info_binh_luan_tra_loi").find('textarea[name="item_binh_luan_in_modal"]').val(my_this);
$("#id_modal_get_info_binh_luan_tra_loi").show();
my_this_html.closest(".div_tra_loi_binh_luan").hide();
} else {
alert("Captcha không đúng");
data = {
'action': 'get_captcha',
'nonce': nonce
}
$.ajax({
dataType: "json",
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
my_this.closest(".div_tra_loi_binh_luan").find(".capImage_tl").attr('src', response.mysrc);
//my_this.closest('.div_tra_loi_binh_luan').find('textarea[name="content_binh_luan_tra_loi"]').val(my_this.attr("id_string_dau"));
my_this.parent().find('input[name="value_captcha_tl"]').val("");
},
});
}
},
});
}
});
$("#btn_binh_luan_modal_tra_loi").click(function () {
my_this = $(this);
if ($('input[name="full_nam_modal_tra_loi"]').val().length < 1) {
alert("Họ tên không hợp lệ");
return false;
}
num_phone_bl_tl = $('input[name="num_phone_bl_tl"]').val();
var isphone = /^(1\s|1|)?((\(\d{3}\))|\d{3})(\-|\s)?(\d{3})(\-|\s)?(\d{4})$/.test(num_phone_bl_tl);
if (!isphone) {
alert("Số điện thoại không hợp lệ");
return false;
}
email_bl_tl = $('input[name="email_bl_tl"]').val();
const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!re.test(email_bl_tl)) {
alert("Email không hợp lệ");
return false;
}
my_this_modal = $("#id_modal_get_info_binh_luan_tra_loi");
var data = {
'action': 'add_xdvncomment_tra_loi_fe',
'nonce': nonce,
//'content_binh_luan_tra_loi': $(this).parent().find('textarea[name="content_binh_luan_tra_loi"]').val(),
'content_binh_luan_tra_loi': $('textarea[name="content_binh_luan_tra_loi_in_modal"]').val(),
'full_nam_modal_tra_loi': $('input[name="full_nam_modal_tra_loi"]').val(),
'num_phone_bl_tl': $('input[name="num_phone_bl_tl"]').val(),
'email_bl_tl': $('input[name="email_bl_tl"]').val(),
//'id_comment_parent': $(this).attr("id_parent"),
'id_comment_parent': $('input[name="parent_modal_tra_loi"]').val(),
'id_pro': id_pro_local,
'value_captcha': $(this).parent().find('input[name="captcha_tra_loi_in_md"]').val(),
};
$.ajax({
dataType: 'json',
type: "POST",
url: ajaxurl,
data: data,
beforeSend: function () {
my_this.prop('disabled', true);
},
success: function (response) {
if (response.is_no_error) {
if (response.option_browser === "pending") {
alert("Trả lời đang chờ duyệt.Cảm ơn bạn đã trả lời.");
} else {
m_this_item = $("#id_item_div_binh_luan_" + response.id_parent);
if (m_this_item.find(".div_wap_show_tra_loi_bt").length <= 0) {
var my_html_append = '' + response.html_ajax + '
';
m_this_item.append(my_html_append);
} else {
m_this_item.find(".div_wap_show_tra_loi_bt").append(response.html_ajax);
}
alert("Cảm ơn bạn đã trả lời, Chúng tôi phản hồi sớm nhất.");
}
$('#id_modal_get_info_binh_luan_tra_loi').hide();
} else {
console.log("loi khi them binh luan");
console.log(response);
}
my_this.prop('disabled', false);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}
});
});
/*end: js for comment*/
});